package training.irpf.business.taxtable;

import java.math.BigDecimal;

public class TabelaIrpf2012 implements ITabelaIrpf {
	private BigDecimal[] ALIQUOTAS = new BigDecimal[] {
		new BigDecimal("0"),
		new BigDecimal("7.5"),
		new BigDecimal("15"),
		new BigDecimal("22.5"),
		new BigDecimal("27.5"),
	};
	
	private BigDecimal[] PARCELAS = new BigDecimal[] {
		new BigDecimal("0"),
		new BigDecimal("1409.95"),
		new BigDecimal("3523.01"),
		new BigDecimal("6340.47"),
		new BigDecimal("8687.45"),			
	};	
	
	public BigDecimal buscarAliquota(BigDecimal base) {
		int indice = buscarIndice(base);
		return ALIQUOTAS[indice];
	}

	public BigDecimal buscarParcela(BigDecimal base) {
		int indice = buscarIndice(base);
		return PARCELAS[indice];
	}
	
	private int buscarIndice(BigDecimal base) {
		if (maior(base, new BigDecimal("46939.56"))) {
			return 4;
		} else if (maior(base, new BigDecimal("37566.12"))) {
			return 3;
		} else if (maior(base, new BigDecimal("28174.20"))) {
			return 2;
		} else if (maior(base, new BigDecimal("18799.32"))) {
			return 1;
		} else {
			return 0;
		}
	}
	
	private boolean maior(BigDecimal x, BigDecimal y) {
		return x.compareTo(y) == 1;
	}
}
